package com.cskaoyan.controller.wx;/*-*- coding = utf-8 -*-
@Time : 2022/11/22 15:08
@Author : 林涂兵
@File : WxSearch.java
@Software: IntelliJ IDEA*/

import com.cskaoyan.bean.common.BaseParam;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.vo.wx.IndexSearchKeyword;
import com.cskaoyan.bean.vo.wx.SearchGoodsAndCategoryListVo;
import com.cskaoyan.service.wx.WxSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("wx/search")
public class WxSearchController {

    @Autowired
    WxSearchService wxSearchServiceImpl;

    /**
     *  搜索界面 传回关键词，热词等信息
     * @return 查询的关键字的结果
     */
    @RequestMapping("index")
    public BaseRespVo indexKeyWord(){
        IndexSearchKeyword datas = wxSearchServiceImpl.selectIndexKeyWord();

        return BaseRespVo.succeed(datas);
    }

    /**
     *  搜索栏 输入一部分关键词出现热词
     * @param keyword
     * @return
     */
    @RequestMapping("helper")
    public BaseRespVo helperKeyWord(String keyword){
        List<String> strings = wxSearchServiceImpl.selectHotKeyword(keyword);

        return BaseRespVo.succeed(strings);
    }

    /**
     *  根据对应的搜索关键字寻找对应的商品
     * @return 对应的数据
*/    /*@RequestMapping("list")
    public BaseRespVo selectGoodsByKeyword(BaseParam baseParam,String keyword,Integer categoryId,Integer brandId){
        // 首先要将当前的关键词存入该用户的历史关键词中
        wxSearchServiceImpl.insertHistoryKeyword(keyword);

        // 查询商品和类目信息
        SearchGoodsAndCategoryListVo goods = wxSearchServiceImpl.selectGoodsByKeyword(baseParam,keyword,categoryId,brandId);

        return BaseRespVo.succeed(goods);
    }*/

    @RequestMapping("clearhistory")
    public BaseRespVo clearHistory(){
        wxSearchServiceImpl.deleteAllHistoryKeywordByUserId();

        return BaseRespVo.succeed();
    }
}
